#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int maxSubarraySumCircular(vector<int>& nums) {
    const int INF = 0x3f3f3f3f;
    int n = nums.size();
    vector<int> f(n + 1, -INF), g(n + 1, INF);
    int sum = 0, nmax = INT_MIN, nmin = INT_MAX;
    for (int i = 1; i <= n; i++)
    {
        f[i] = max(f[i - 1], 0) + nums[i - 1];
        g[i] = min(g[i - 1] + nums[i - 1], nums[i - 1]);
        sum += nums[i - 1];
        nmax = max(nmax, f[i]);
        nmin = min(nmin, g[i]);
    }
    if (sum == nmin) return nmax;
    return max(nmax, sum - nmin);
}

int getMaxLen(vector<int>& nums) {
    int n = nums.size();
    vector<int> f(n + 1);
    auto g = f;
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        if (nums[i - 1] > 0)
        {
            f[i] = f[i - 1] + 1;
            g[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
        }
        else if (nums[i - 1] < 0)
        {
            f[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
            g[i] = f[i - 1] + 1;
        }
        res = max(res, f[i]);
    }
    return res;
}

int numberOfArithmeticSlices(vector<int>& nums) {
    int n = nums.size();
    vector<int> f(n);
    for (int i = 2; i < n; i++)
        if (nums[i] + nums[i - 2] == 2 * nums[i - 1])
            f[i] = f[i - 1] + 1;

    int res = 0;
    for (int i = 2; i < n; i++)    res += f[i];
    return res;
}